import Base64 from 'base-64';
const BASE_IP:string = import.meta.env.VITE_PUBLIC_IP;
const BASE_PORT:string = import.meta.env.VITE_PUBLIC_PORT;
const BASE_PREVIEW_PORT:string = import.meta.env.VITE_PUBLIC_PREVIEW_PORT;
const PREVIEW_FTP_URI:string = import.meta.env.VITE_PUBLIC_FTP_PREVIEW_URI;
const PREVIEW_LOG_URI:string = import.meta.env.VITE_PUBLIC_LOG_PREVIEW_URI;

const COMPLETE_FTP_URL_PRE:string = 'http://' + BASE_IP + ':' + BASE_PORT + PREVIEW_FTP_URI;
const COMPLETE_LOG_URL_PRE:string = 'http://' + BASE_IP + ':' + BASE_PORT + PREVIEW_LOG_URI;
const COMPLETE_PREVIEW_URL:string = 'http://' + BASE_IP + ':' + BASE_PREVIEW_PORT;

/**
 * 拼接日志文件地址
 * @param fileName 文件名称
 */
export const concatLogUrl = (fileName: string) => {
    return COMPLETE_LOG_URL_PRE + fileName;
}

/**
 * 拼接ftp文件地址
 * @param fileName 文件名称
 */
export const concatFtpUrl = (fileName: string) => {
    return COMPLETE_FTP_URL_PRE + fileName;
}

/**
 * 浏览器新tab预览
 * @param url
 */
export const previewFun = (url: string) => {
    window.open(COMPLETE_PREVIEW_URL + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(url)));
}